home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example8.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  5KB  |  163 lines

  1. /* Example8                                                    */
  2. /* This program explains how to use the IDCMP flag INTUITICKS. */
  3.  
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7.  
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13.  
  14. /* Declare a pointer to a Window structure: */ 
  15. struct Window *my_window;
  16.  
  17. /* Declare and initialize your NewWindow structure: */
  18. struct NewWindow my_new_window=
  19. {
  20.   50,             /* LeftEdge    x position of the window. */
  21.   25,             /* TopEdge     y positio of the window. */
  22.   320,            /* Width       320 pixels wide. */
  23.   100,            /* Height      100 lines high. */
  24.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  25.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  26.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  27.                   /*             selects the Close window gad.           */
  28.  
  29.   INTUITICKS,     /*             We will also recieve simple time */
  30.                   /*             events. (Around 10 times / second.) */
  31.  
  32.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  33.   WINDOWCLOSE|    /*             Close Gadget. */
  34.   WINDOWDRAG|     /*             Drag gadget. */
  35.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  36.   WINDOWSIZING|   /*             Sizing Gadget. */
  37.   ACTIVATE,       /*             The window should be Active when opened. */
  38.   NULL,           /* FirstGadget No gadgets connected to this window. */
  39.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  40.   "THE TIME IS SHORT",/* Title   Title of the window. */
  41.   NULL,           /* Screen      Connected to the Workbench Screen. */
  42.   NULL,           /* BitMap      No Custom BitMap. */
  43.   100,            /* MinWidth    We will not allow the window to become */
  44.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  45.   400,            /* MaxWidth    than 400 x 200. */
  46.   200,            /* MaxHeight */
  47.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  48. };
  49.  
  50.  
  51.  
  52. /*************************************************************************/
  53. /* Extra information:                                                    */
  54. /* INTUITICKS is a simply way of getting time messages. We will get      */
  55. /* around (!) 10 messages per second. The nice thing with these messages */
  56. /* is that it will not fill up the input buffer if you do not collect    */
  57. /* them fast enough. If Intuition finds an INTUITICK message already     */
  58. /* waiting in the port, no new messages will be created.                 */
  59. /*************************************************************************/
  60.  
  61.  
  62.  
  63. main()
  64. {
  65.   /* Boolean variable used for the while loop: */
  66.   BOOL close_me;
  67.  
  68.   ULONG class;   /* IDCMP flag. */
  69.  
  70.   ULONG seconds; /* Seconds, copy of the system clock. */
  71.   ULONG micros;  /* Micros,           - " -            */
  72.  
  73.   /* Pointer to an IntuiMessage structure: */
  74.   struct IntuiMessage *my_message;
  75.  
  76.  
  77.  
  78.   /* Before we can use Intuition we need to open the Intuition Library: */
  79.   IntuitionBase = (struct IntuitionBase *)
  80.     OpenLibrary( "intuition.library", 0 );
  81.   
  82.   if( IntuitionBase == NULL )
  83.     exit(); /* Could NOT open the Intuition Library! */
  84.  
  85.  
  86.  
  87.   /* We will now try to open the window: */
  88.   my_window = (struct Window *) OpenWindow( &my_new_window );
  89.   
  90.   /* Have we opened the window succesfully? */
  91.   if(my_window == NULL)
  92.   {
  93.     /* Could NOT open the Window! */
  94.     
  95.     /* Close the Intuition Library since we have opened it: */
  96.     CloseLibrary( IntuitionBase );
  97.  
  98.     exit();  
  99.   }
  100.  
  101.  
  102.  
  103.   /* We have opened the window, and everything seems to be OK. */
  104.  
  105.  
  106.  
  107.   close_me = FALSE;
  108.  
  109.   /* Stay in the while loop until the user has selected the Close window */
  110.   /* gadget: */
  111.   while( close_me == FALSE )
  112.   {
  113.     /* Wait until we have recieved a message: */
  114.     Wait( 1 << my_window->UserPort->mp_SigBit );
  115.  
  116.  
  117.     /* As long as we can collect messages successfully we stay in the */
  118.     /* while-loop: */
  119.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  120.     {
  121.       /* After we have successfully collected the message we can read */
  122.       /* it, and save any important values which we maybe want to check */
  123.       /* later: */
  124.       class = my_message->Class;     /* IDCMP flag. */
  125.       
  126.       /* Copies of the system clock when this message was created: */
  127.       seconds = my_message->Seconds; /* Seconds. */
  128.       micros = my_message->Micros;   /* Micros. */
  129.  
  130.  
  131.       /* After we have read it we reply as fast as possible: */
  132.       /* REMEMBER! Do never try to read a message after you have replied! */
  133.       /* (Some other process has maybe changed it.) */
  134.       ReplyMsg( my_message );
  135.  
  136.  
  137.       /* Check which IDCMP flag was sent: */
  138.       switch( class )
  139.       {
  140.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  141.                close_me=TRUE;
  142.                break;
  143.  
  144.         case INTUITICKS:     /* Time event. */
  145.                printf("Seconds: %6d  Micros: %6d\n", seconds, micros);
  146.                break;
  147.       }
  148.     }
  149.   }
  150.  
  151.  
  152.  
  153.   /* Close the window: */
  154.   CloseWindow( my_window );
  155.  
  156.  
  157.  
  158.   /* Close the Intuition Library: */
  159.   CloseLibrary( IntuitionBase );
  160.   
  161.   /* THE END */
  162. }
  163.